package com.qxglxt.qxglxt.service;

import java.util.List;

import javax.annotation.Resource;

import com.qxglxt.qxglxt.dao.IRolesDao;
import com.qxglxt.qxglxt.dao.IUsersDao;
import com.qxglxt.qxglxt.model.Modules;
import com.qxglxt.qxglxt.model.Roles;

import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl implements IRoleService {

    @Resource
    private IRolesDao rolesDao;
    @Resource
    private IUsersDao userDao;

    @Override
    public void setRoleModules(String RoleId, List<String> modulesIdList) {
        Roles roles=rolesDao.getOne(RoleId);
        for(String moduleId:modulesIdList){
            Modules modules=new Modules();
            modules.setId(moduleId);
            roles.getModulesList().add(modules);
        }
        rolesDao.save(roles);

    }

    @Override
    public List<Roles> findUserRoles(String userId) {
        return userDao.getOne(userId).getRolesList();
    }

}